<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="区站号" prop="stationIdC">
        <el-select v-model="queryParams.stationIdC" placeholder="请选择区站号" clearable filterable size="small">
          <el-option
            v-for="item in stationOptions"
            :key="item.stationId"
            :label="item.stationName + ',' + item.stationIdC"
            :value="item.stationIdC">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['modules:dataUsable:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dataUsableList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="要素ID" align="center" prop="surfId" v-if="false"/>
      <el-table-column label="区站号" align="center" prop="stationIdC" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="访问轮次" align="center" prop="requestNum" />
      <el-table-column label="无观测任务" align="center" prop="noTask" />

      <el-table-column label="可用数据" align="center" prop="usableStr" />
      <el-table-column label="可用个数" align="center" prop="usableNum" />
      <el-table-column label="可用率" align="center" prop="usableRate" />

      <el-table-column label="缺测数据" align="center" prop="missStr" />
      <el-table-column label="缺测个数" align="center" prop="missNum" />
      <el-table-column label="缺测率" align="center" prop="missRate" />

      <el-table-column label="错误数据" align="center" prop="errorStr" />
      <el-table-column label="错误个数" align="center" prop="errorNum" />
      <el-table-column label="错误率" align="center" prop="errorRate" />

      <el-table-column label="可疑数据" align="center" prop="suspiciousStr" />
      <el-table-column label="可疑个数" align="center" prop="suspiciousNum" />
      <el-table-column label="可疑率" align="center" prop="suspiciousRate" />

      <el-table-column label="未质控数据" align="center" prop="controlStr" />
      <el-table-column label="未质控个数" align="center" prop="controlNum" />
      <el-table-column label="未质控率" align="center" prop="controlRate" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listInfoByDto} from "@/api/modules/info";
import {listDataUsable, exportDataUsable} from "@/api/modules/dataUsable";

export default {
  name: "DataUsable",
  data(){
    return{
      // 数据可用性统计表格数据
      dataUsableList: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 站点选择列表
      stationOptions:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stationIdC: undefined,
      },
    }
  },
  created() {
    this.init();
    this.getList();
  },
  methods:{
    /** 网页初始化 */
    init(){
      let selectDto = {
        stationState:1
      };
      listInfoByDto(selectDto).then(res=>{
        this.stationOptions = res.data;
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.surfId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 查询数据可用性统计列表 */
    getList() {
      this.loading = true;
      console.log('22222')
      listDataUsable(this.queryParams).then(response => {
        this.dataUsableList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据可用性数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportDataUsable(queryParams);
      }).then(response => {
        this.download(response.msg);
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>

<style scoped>

</style>
